<template>
  <div class="container">
    <Navbar title="我的消息"></Navbar>
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="已经到底了"
      @load="onLoad"
    >
      <div class="message-item" v-for="item in messages" :key="item.id">
        <div class="order">{{item.data.message}}</div>
        <div class="date">{{item.created_at | formatTime}}</div>
      </div>
    </van-list>
  </div>
</template>

<script>
import Navbar from '@/components/common/Navbar';
import { getMessage } from '@/network/member';

export default {
  components: {
    Navbar,
  },
  data() {
    return {
      loading: false,
      finished: false,
      messages: [],
    };
  },
  methods: {
    onLoad() {
      getMessage(this.messages.page).then((res) => {
        this.messages.push(...res.data.data);
        this.loading = false;
        if (this.messages.length >= res.data.total) {
          this.finished = true;
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
.message-item {
  padding: 4px 16px;
  height: 60px;
  line-height: 26px;
  color: rgba(0, 0, 0, .4);
  border-top: 1px solid rgba(0, 0, 0, .04);
  .date {
    font-size: 12px;
  }
}
</style>
